import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:moose_app/core/model/poetry_author_info_model.dart';
import 'package:moose_app/core/utils/navigate_util.dart';
import 'package:moose_app/ui/screens/detail/author/detail_author_screen.dart';
import 'package:moose_app/ui/values/values.dart';
import 'package:moose_app/ui/widgets/operator_view.dart';
import 'package:moose_app/ui/widgets/user/user_avatar.dart';

class ATHRankingItem extends StatelessWidget {
  final PoetryAuthorInfoModel authorInfo;

  ATHRankingItem({this.authorInfo});

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: kSize20),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          ATHDiscoveryUserInfoItem(authorInfo: authorInfo),
          ATHDiscoveryCardItem(authorInfo: authorInfo),
          ATHDiscoveryOperatorItem(),
          Divider()
        ],
      ),
    );
  }
}

class ATHDiscoveryOperatorItem extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      height: kSize100,
      padding: EdgeInsets.only(top: kSize20),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          Container(
            padding: EdgeInsets.symmetric(vertical: kSize4, horizontal: kSize8),
            decoration: BoxDecoration(
                color: kColorPrimaryLight,
                borderRadius: BorderRadius.all(Radius.circular(kSize8))),
            child: Text(
              '诗人',
              style: TextStyle(fontSize: kFontSize26, color: kColor99),
            ),
          ),
          ATHOperatorView(),
          SvgPicture.asset(
            "assets/icons/icon_close_r.svg",
            height: kSize40,
          ),
        ],
      ),
    );
  }
}

class ATHDiscoveryCardItem extends StatelessWidget {
  final PoetryAuthorInfoModel authorInfo;

  ATHDiscoveryCardItem({this.authorInfo});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        print('ATHDiscoveryDetailScreen');
      },
      child: ClipRRect(
        borderRadius: BorderRadius.all(Radius.circular(kSize8)),
        child: Container(
          height: kSize300,
          child: Row(
            children: <Widget>[
              Container(
                width: kSize250,
                decoration: kCommonBoxDecoration,
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: <Widget>[
                    Column(
                      children: <Widget>[
                        SvgPicture.asset(
                          'assets/icons/icon_trophy.svg',
                          width: kSize60,
                          height: kSize60,
                        ),
                        Padding(
                          padding:
                              EdgeInsets.only(bottom: kSize12, top: kSize24),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.center,
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: <Widget>[
                              SvgPicture.asset(
                                'assets/icons/icon_hot.svg',
                                width: kSize30,
                                height: kSize30,
                              ),
                              Padding(
                                padding: EdgeInsets.only(left: kSize8),
                                child: Text(
                                  "${authorInfo?.collected ?? "890"}",
                                  style: TextStyle(
                                      fontSize: kFontSize32,
                                      color: Colors.orangeAccent),
                                ),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                    Text(
                      "2020-12-31",
                      style: TextStyle(
                        color: kColor66,
                        fontSize: kFontSize24,
                      ),
                    ),
                    Text(
                      "${authorInfo?.dynasty ?? "唐朝"}",
                      style: TextStyle(color: kColor33, fontSize: kSize28),
                    ),
                  ],
                ),
              ),
              Expanded(
                child: Stack(
                  children: <Widget>[
                    Positioned(
                      left: 0,
                      right: 0,
                      top: 0,
                      bottom: 0,
                      child: ClipRRect(
                        borderRadius: BorderRadius.only(
                            topLeft: Radius.circular(kSize8),
                            bottomLeft: Radius.circular(kSize8)),
                        child: Image.asset('assets/images/guide-1.jpg',
                            fit: BoxFit.cover),
                      ),
                    ),
                    Positioned(
                        right: kSize16,
                        top: kSize16,
                        child: ClipRRect(
                          borderRadius:
                              BorderRadius.all(Radius.circular(kSize8)),
                          child: Container(
                            width: kSize100,
                            height: kSize48,
                            decoration: BoxDecoration(
                                gradient: LinearGradient(colors: [
                              kColorFF5000,
                              kColorFF6200,
                            ])),
                            alignment: Alignment.center,
                            child: Text(
                              'Top 1',
                              style: TextStyle(
                                  color: Colors.white, fontSize: kSize26),
                            ),
                          ),
                        ))
                  ],
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}

class ATHDiscoveryUserInfoItem extends StatelessWidget {
  final PoetryAuthorInfoModel authorInfo;

  ATHDiscoveryUserInfoItem({this.authorInfo});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        print("authorDetailInfo");
      },
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Row(
            children: <Widget>[
              Container(
                padding: EdgeInsets.symmetric(vertical: kSize20),
                child: Column(
                  children: <Widget>[
                    GestureDetector(
                      onTap: () {
                        ATHNavigator.pushFromRight(
                            context, ATHDetailAuthorScreen.routeName);
                      },
                      child: ClipRRect(
                        borderRadius:
                            BorderRadius.all(Radius.circular(kSize30)),
                        child: ATHUserAvatar(),
                      ),
                    ),
                  ],
                ),
              ),
              Padding(
                padding: EdgeInsets.only(left: kSize16),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      authorInfo?.authorName ?? '李白',
                      style: TextStyle(fontSize: kFontSize36),
                    ),
                    Text(
                      '黄河之水天上来...',
                      style: TextStyle(fontSize: kFontSize26),
                    )
                  ],
                ),
              ),
            ],
          ),
          Container(
            height: kSize60,
            child: ElevatedButton(
              child: Text("关注"),
              style: ButtonStyle(
                  backgroundColor: MaterialStateProperty.all(kColorPrimary),
                  elevation: MaterialStateProperty.all(0),
                  shadowColor: MaterialStateProperty.all(Colors.white),
                  textStyle: MaterialStateProperty.all(
                      TextStyle(color: Colors.white, fontSize: kFontSize28))),
              onPressed: () {
                EasyLoading.showToast('关注');
              },
            ),
          )
        ],
      ),
    );
  }
}
